package com.wwz.dao;

import com.alibaba.fastjson.JSONObject;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
public interface OrderDao {
    @Insert(value = "insert into tb_order(name,branch_id,num) values(#{name},#{branchId},#{num})")
    int insert(@Param("name")String name,@Param("branchId")long branchId,@Param("num")Integer num);

    @Delete(value = "delete from  tb_order where branch_id=#{branchId}")
    int delete(@Param("branchId")String branchId);

    @Update(value = "update  tb_product set num = num-#{name} where id=#{id}")
    int update(@Param("name")String name,@Param("id")long id);

    @Insert(value = "<script> insert into tb_order(name,branch_id,num,seata_id) values " +
            "" +
            "" +
            "<foreach item='item'   collection='list' separator=','>" +
            "(#{item.name},#{item.branch_id},#{item.num},#{branchId})" +
            "</foreach> </script>")
    int batchInsert(@Param("list")List<JSONObject> list, @Param("branchId")long branchId);


    @Delete(value = "<script>delete from  tb_order where branch_id in (" +
            "" +
            "<foreach item='it' collection='list' separator=','>" +
            "#{it.branch_id}" +
            "</foreach>" +
            ")</script>")
    int batchDelete(@Param("list")List<JSONObject> list);
}
